Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Coding rule to detect usages of old time and date classes (#1384 / #1385) #1385

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Bukama
Copy link

@Bukama Bukama commented Nov 27, 2024

Update:

Provided commit message

General coding rule to detect usages of old time and date classes (#1384 / #1385)

With this commit new general rules are added which detect the usages of old
time and date classes, e.g. java.util.Date.

closes #1384

I would like to provide rules for #1384, but I'm failing with the OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED_should_fail_when_class_uses_java_util_date test as my violation is not captured, but this

[violation details (should have some detail containing 'since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.')]
Expecting any elements of:
["Method <com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaUtilDate.usesJavaUtilDate()> calls method <java.util.Date.from(java.time.Instant)> in (UsesJavaUtilDate.java:9)"]
to match given predicate but none did.
java.lang.AssertionError: [violation details (should have some detail containing 'since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.')]
Expecting any elements of:
["Method <com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaUtilDate.usesJavaUtilDate()> calls method <java.util.Date.from(java.time.Instant)> in (UsesJavaUtilDate.java:9)"]
to match given predicate but none did.

Can anyone give me a hint how to fix that?

P.S. I know that my formatting (e.g. star import) are not yet correct. Will fix this when my tests are working and before changing this draft into a real PR, including providing a real commit message.

@hankem
Copy link
Member

hankem commented Nov 27, 2024

Thanks for your contribution! I think that your confusion is that

since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.

is part of the rule description, but you're testing the violation description, which is

Method <com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaUtilDate.usesJavaUtilDate()> calls method <java.util.Date.from(java.time.Instant)> in (UsesJavaUtilDate.java:9)

@Bukama
Copy link
Author

Bukama commented Nov 28, 2024

Thanks for your contribution! I think that your confusion is that

since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.

is part of the rule description, but you're testing the violation description, which is

Method <com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaUtilDate.usesJavaUtilDate()> calls method <java.util.Date.from(java.time.Instant)> in (UsesJavaUtilDate.java:9)

Thanks that helped!

@Bukama Bukama marked this pull request as ready for review November 28, 2024 16:07
@Bukama Bukama changed the title General Coding rule to detect usages of old time and date classes (DRAFT for #1384) General Coding rule to detect usages of old time and date classes (#1384 / #1385) Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants